package com.hishop.product.web;

import com.hishop.product.entity.CategoryEntity;
import com.hishop.product.service.CategoryService;
import com.hishop.product.vo.Catelog2Vo;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ExecutionException;

@Controller
public class IndexController {
    @Resource
    CategoryService categoryService;

    @GetMapping({"/","/index.html"})
    public String indexPage(Model model){
        //查询所有的一级分类
        List<CategoryEntity> categoryEntities = categoryService.getLevel1Categorys();
        model.addAttribute("categoryes",categoryEntities);
        return "index";
    }

    //index/json/catalog.json
    @GetMapping(value = "/index/catalog.json")
    @ResponseBody
    public Map<String, List<Catelog2Vo>> getCatalogJson() {

        Map<String, List<Catelog2Vo>> catalogJson = categoryService.getCatalogJson();

        return catalogJson;

    }

//    @GetMapping("/item.html")
//    public String skuItem(){
//
////        System.out.println("准备查询" + skuId + "详情");
//
////        SkuItemVo vos = skuInfoService.item(skuId);
////
////        model.addAttribute("item",vos);
//
//        return "item";
//    }
}
